<template>
  <div class="my-blog">
    <!-- <Button type="primary" icon="md-add">新增</Button> -->
    <div class="box">
      <div class="item" v-for="item in list" :key="item.id">
        <div class="top">
          <div class="title">{{item.title}}</div>
          <div class="date">{{item.startdate}} - {{item.enddate}}</div>
        </div>
        <div class="bottom">
          <div class="left">
            {{item.brief}}
          </div>
          <div class="right">
            <span @click="edit(item.id)">编辑</span>
            <span @click="seeProject(item.id)">查看</span>
            <span @click="deleteProjectHandle(item)">删除</span>
          </div>
        </div>
      </div>
    </div>
    <Modal v-model="ifSeeBlog" :fullscreen="true" footer-hide :title="seeProjectTitle">
      <div class="quill-editor" v-html="seeProjectData"></div>
    </Modal>
  </div>
</template>
<script>
import { quillEditor } from "vue-quill-editor";
import "quill/dist/quill.snow.css";
import { getProject, getProjectById, deleteProject } from '@/api/server.js';
export default {
  components: {
    quillEditor
  },
	created(){
		
	},
  mounted() {
    this.getProjectHandle({currentPage:1, pageSize: 1000});
  },
  data() {
    return {
      list: [],
      ifSeeBlog: false,
      seeProjectData: "",
      seeProjectTitle: "",
    };
  },
	methods:{
    getProjectHandle(param) {
      getProject(param).then(res => {
        this.list = res.data;
      })
    },
		edit(id) {
      this.$router.push({
        path: "/project-edit",
        query: {id: id}
      });
    },
    seeProject(id) {
      this.ifSeeBlog = true;
      getProjectById({'id':id}).then(res => {
        this.seeProjectData = res.data.content;
        this.seeProjectTitle = res.data.title;
      })
    },
    deleteProjectHandle(item) {
      this.$Modal.confirm({
        title:'删除提示',
        content:`确定删除博客${item.title}吗？`,
        // okText: '确定',
        onOk: () => {
          deleteProject({id:item.id}).then(res => {
            if(res.data) {
              $Message.success('删除成功');
              this.getProjectHandle({currentPage:1, pageSize: 1000});
            }else {
              $Message.error('删除失败');
            }
          })
        },
        onCancel: () => {

        },

      })
      
    },
	},
};
</script>

<style lang="less" scoped>
.my-blog {
  .box {
    .item {
      padding-bottom: 10px;
      margin-bottom: 20px;
      border-bottom: 1px solid #ddd;
      .top {
        display: flex;
        justify-content: space-between;
        margin-bottom: 20px;
        .title {
          font-size: 16px;
          font-weight: 700;
          color: #555666;
        }
        .date {
          font-size: 14px;
          color: #999;
        }
      }
      .bottom {
        display: flex;
        justify-content: space-between;
        .left {
          color: #999aaa;
          font-size: 14px;
        }
        .right {
          color: #F99C34;
          font-size: 14px;
          &>span {
            margin-left: 10px;
            cursor: pointer;
          }
        }
      }
    }
  }
  
}
</style>